#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import os, sys, datetime, time, sqlacodegen

from sicost.config import app_config


def main():
    profile = (sys.argv[1].split("=", 1)[-1]) if len(sys.argv) > 1 else 'prod'
    config = app_config[profile]

    """
    在虚拟环境目录下执行
    """

    # NOTE db2 https://github.com/ibmdb/python-ibmdbsa/tree/master/ibm_db_sa
    """
    db2+ibm_db://{USER}:{PASS}@{HOST}:{PORT}/{DB_NAME}
    ibm_db_sa://{USER}:{PASS}@127.0.0.1:{PORT}/{DB_NAME}
    """
    cmd = 'sqlacodegen --outfile ./models/mpp.py db2+ibm_db://{}:{}@{}:{}/{}'.format(config.DB_USER_MPP_DB2,
                                                                                     config.DB_PASSWORD_MPP_DB2,
                                                                                     config.DB_HOST_MPP_DB2,
                                                                                     config.DB_PORT_MPP_DB2,
                                                                                     config.DB_DBNAME_MPP_DB2)
    os.system(cmd)
    cmd = 'sqlacodegen --outfile ./models/dbprod7.py db2+ibm_db://{}:{}@{}:{}/{}'.format(config.DB_USER_DBPROD7_DB2,
                                                                                         config.DB_PASSWORD_DBPROD7_DB2,
                                                                                         config.DB_HOST_DBPROD7_DB2,
                                                                                         config.DB_PORT_DBPROD7_DB2,
                                                                                         config.DB_DBNAME_DBPROD7_DB2)
    os.system(cmd)

    # NOTE oracle
    """
    engine = create_engine('oracle://scott:tiger@127.0.0.1:1521/sidname')
    engine = create_engine('oracle+cx_oracle://scott:tiger@tnsname')
    """
    cmd = ''

    # NOTE mysql
    """
    # default
    engine = create_engine('mysql://scott:tiger@localhost/foo')
    # mysql-python
    engine = create_engine('mysql+mysqldb://scott:tiger@localhost/foo')
    # MySQL-connector-python
    engine = create_engine('mysql+mysqlconnector://scott:tiger@localhost/foo')
    # OurSQL
    engine = create_engine('mysql+oursql://scott:tiger@localhost/foo')
    """
    cmd = 'sqlacodegen --outfile ./models/match.py mysql+pymysql://root:Welcome%4013579@localhost/match?charset=utf8'
    # os.system(cmd)

    # NOTE ms-sql
    """
    # pyodbc
    engine = create_engine('mssql+pyodbc://scott:tiger@mydsn')
    # pymssql
    engine = create_engine('mssql+pymssql://scott:tiger@hostname:port/dbname')
    """

    return 0


if __name__ == '__main__':
    start = datetime.datetime.now()

    status = main()

    elapsed = float((datetime.datetime.now() - start).seconds)
    print("Time Used 4 All ----->>>> %f seconds" % (elapsed))
